{include file="common/header" /}
<style>
    body {
        background-color: #ffffff;
    }
</style>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" name="act" value="{$act}" >
    <input type="hidden" name="admin_id" value="{$admin_id}">
    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" class="layui-input" value="{$info.username}" readonly="">
            <tip>填写自己管理账号的名称。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label ">密码</label>
        <div class="layui-input-block">
            <input type="text" class="layui-input" name="password"  value="" autocomplete="off" placeholder="请输入密码">
            <tip>{if condition="$act eq 'add'"}不输入为123456{else/}不修改不输入{/if}</tip>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="number" name="mobile" lay-reqtext="手机不能为空" placeholder="请输入手机" value="{$info.mobile}" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email"  placeholder="请输入邮箱" value="{$info.email}" class="layui-input">
            <tip>填写自己管理账号的名称。</tip>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-block">
          <select name="role_id" >
            {volist name="$ad_role_res" id="vo"}
            <option value="{$vo.role_id}"  {if $info.role_id == $vo.role_id /} selected="" {/if}  >{$vo.role_name}</option>
            {/volist}
          </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>

<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.load(1, {
                shade: [0.3,'#000'] //0.1透明度的白色背景
            });
            var data = data.field;
            $.ajax({
                url:"{:url('Admin/edit')}",
                data:data,
                type:'post',
                dataType:'json',
                success:function(res){
                    // console.log(res)
                    // return false
                    if(res.errcode != 1){
                        layer.msg(res.message,{icon: 2,time: 2000},function(){
                            layer.close(index);
                        })
                    }else{
                        layer.msg(res.message,{icon: 1,time: 1000},function () {
                            layer.close(index);
                            var parent_index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            parent.layer.close(parent_index);  // 关闭layer
                            // window.location.href = res.dyurl;
                            parent.location.reload();
                        })
                    }
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.msg('网络失败，请刷新页面后重试!',{icon: 2,time: 2000})
                }
            });

            return false;
        });

    });
</script>
</body>
</html>